<extend name="public:template"/>

<block name="title">新增管理员</block>

<block name="content">
    <div class="wrap-page">
        <div id="pageMemberInfo" class="page-content">
            <include file="public:subtabs"/>
            <form class="form default-style" role="form" action="{:u('backend/admin/add')}" method="post">

                <div id="tabSwitchProduct" class="tab-switch">

                    <!--选项卡-->
                    <div class="tabs-title clearfix">
                        <ul>
                            <li class="current"><a data-id="tab-basic" href="javascript:;">基本信息</a></li>
                            <!--<li><a data-id="tab-account" href="javascript:;">账户资金</a></li>-->
                        </ul>
                    </div>
                    <!--选项卡-->

                    <!--编辑区域-->
                    <div class="tab-content">
                        <div id="tab-basic-content" class="tab-content-inner">
                            <div id="boxBasicInfo" class="box">
                                <div class="box-content">

                                    <dl class="clearfix">
                                        <dt><label>管理员：</label></dt>
                                        <dd>
                                            <div class="item-field clearfix">
                                                <input id="username" placeholder="请输入管理员名" class="textfield" type="text" value="" name="username"  autocomplete="off"/>
                                            </div>
                                        </dd>
                                    </dl>
                                    <dl class="clearfix">
                                        <dt><label>所属角色：</label></dt>
                                        <dd>
                                            <div class="item-field clearfix">
                                                <select name="role" id="role" class="select" style="width:200px;">
                                                    <volist name="role_list" id="vo">
                                                        <option  value="{$vo.id}" <if condition="$vo.role_id eq $data.role_id"> selected="selected" </if>>{$vo.name}</option>
                                                    </volist>
                                                </select>
                                            </div>
                                        </dd>
                                    </dl>
                                    <dl class="clearfix">
                                        <dt><label>密码：</label></dt>
                                        <dd>
                                            <div class="item-field clearfix">
                                                <input id="password" placeholder="请输入密码" class="textfield" type="password" name="password" autocomplete="off" />
                                            </div>
                                        </dd>
                                    </dl>
                                    <dl class="clearfix">
                                        <dt><label>确认密码：</label></dt>
                                        <dd>
                                            <div class="item-field clearfix">
                                                <input id="repassword" placeholder="请输入确认密码" class="textfield" type="password" name="repassword"  autocomplete="off"/>
                                            </div>
                                        </dd>
                                    </dl>

                                    <dl class="clearfix">
                                        <dt><label>手机号码：</label></dt>
                                        <dd>
                                            <div class="item-field clearfix">
                                                <input id="mobile" placeholder="请输入手机号码"  class="textfield" type="text" name="mobile" value=""  autocomplete="off"/>
                                            </div>
                                        </dd>
                                    </dl>
                                    <dl class="clearfix">
                                        <dt><label for="email">电子邮箱：</label></dt>
                                        <dd>
                                            <div class="item-field clearfix">
                                                <input id="email" placeholder="请输入邮箱" class="textfield" type="text" name="email" value=""  autocomplete="off"/>
                                            </div>
                                        </dd>
                                    </dl>

                                    <dl class="clearfix">
                                        <dt><label>状态：</label></dt>
                                        <dd>
                                            <div class="item-field clearfix">
                                                <div class="radio-layout-h clearfix">
                                                    <div class="radio-item">
                                                        <span class="radio-field"><input class="radio" value="1" name="status" type="radio" checked /></span>
                                                        <span class="radio-text"><label >启用</label></span>
                                                    </div>
                                                    <div class="radio-item">
                                                        <span class="radio-field"><input class="radio"  value="0" name="status" type="radio" /></span>
                                                        <span class="radio-text"><label >禁用</label></span>
                                                    </div>
                                                </div>
                                            </div>
                                        </dd>
                                    </dl>

                                </div>
                            </div>
                        </div>
                    </div>
                    <!--编辑区域END-->
                </div>
                <div class="page-buttons clearfix">
                    <div class="fl-l">
                        <button type="button" class="button button-blue" id="save">保存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</block>
<block name="script">
    <script>
        $(document).ready(function(){
            $('#mytab a').click(function (e) {
                e.preventDefault()
                $(this).tab('show')
            })

            $('#save').click(function(){
                var name       = $.trim($('#username').val());
                var email      = $.trim($('#email').val());
                var mobile     = $.trim($('#mobile').val());
                var password       = $.trim($('#password').val());
                var repassword     = $.trim($('#repassword').val());

                if(!name)
                {
                    $('#username').val('').focus();
                    layer.tips('请输入管理员名称', '#username', {
                        tips: [2, '#009f95'],
                        time: 3000
                    });
                    return false;
                }
                if(!password)
                {
                    $('#password').val('').focus();
                    layer.tips('请输入密码', '#password', {
                        tips: [2, '#009f95'],
                        time: 3000
                    });
                    return false;
                }

                if(!repassword)
                {
                    $('#repassword').val('').focus();
                    layer.tips('请输入确认密码', '#repassword', {
                        tips: [2, '#009f95'],
                        time: 3000
                    });
                    return false;
                }

                if(repassword != password)
                {
                    $('#repassword').val('').focus();
                    layer.tips('两次密码输入不一致', '#repassword', {
                        tips: [2, '#009f95'],
                        time: 3000
                    });
                    return false;
                }

                if(!email)
                {
                    $('#email').val('').focus();
                    layer.tips('请输入邮箱', '#email', {
                        tips: [2, '#009f95'],
                        time: 3000
                    });
                    return false;
                }

                if(!verifyformat(reg_email,email))
                {
                    $('#email').focus();
                    layer.tips('邮箱格式不正确', '#email', {
                        tips: [2, '#009f95'],
                        time: 3000
                    });
                    return false;
                }

                if(!mobile)
                {
                    $('#mobile').val('').focus();
                    layer.tips('请输入手机号', '#mobile', {
                        tips: [2, '#009f95'],
                        time: 3000
                    });
                    return false;
                }

                if(!verifyformat(reg_mobile,mobile))
                {
                    $('#mobile').focus();
                    layer.tips('手机格式不正确', '#mobile', {
                        tips: [2, '#009f95'],
                        time: 3000
                    });
                    return false;
                }

                //数据验证
                $.ajax({
                    type: "POST",
                    url: $('.form').attr('action'),
                    data: $('.form').serialize(),
                    dataType: "json",
                    success:function(data){
                        if(data.status)
                        {
                            layer.msg(data.msg,{icon: 1,time:2000, shade: [0.1, '#ccc']},function(){
                                window.location.href="{:u('backend/admin/index')}";
                            })
                        } else {
                            layer.msg(data.msg,{icon: 2,time:2000, shade: [0.1, '#ccc']})
                        }
                    }
                });
                return false;
            });
        });
    </script>
</block>